local skel = fk.CreateSkill {
  name = "lb_old__hairu",
}

Fk:loadTranslationTable {
  ["lb_old__hairu"] = "骇入",
  --[":lb_old__hairu"] = "出牌阶段，你可将一张非基本牌暗置于没有「<b>骇入</b>」牌的角色的武将牌上直到本轮结束，若为<font color='red'>红</font>/黑色，其<font color='red'>回复体力</font>/造成伤害时弃置之并将之改为<font color='red'>受到等量伤害</font>/令原受伤者回复等量体力。",
  --8.30
  --[":lb_old__hairu"] = "出牌阶段，你可将一张非基本牌暗置于没有「<b>骇入</b>」牌的角色的武将牌上直到下轮或其下个回合结束，若为<font color='red'>红</font>/黑色，其<font color='red'>回复体力</font>/造成伤害时弃置之并将之改为<font color='red'>受到等量伤害</font>/令原受伤者回复等量体力。",
  --8.30 2
  [":lb_old__hairu"] = "出牌阶段，你可将一张非基本牌暗置于没有「<b>骇入</b>」牌的角色的武将牌上，若为<font color='red'>红</font>/黑色，其<font color='red'>回复体力</font>/造成伤害时弃置之并将之改为<font color='red'>受到等量伤害</font>/令原受伤者回复等量体力。",


  ["$lb_old__hairu"] = "骇入",
  ["#lb_old__hairu"] = "骇入：将一张非基本牌暗置于没有<b>骇入</b>牌的角色的武将牌上",

  ["$lb_old__hairu1"] = "这次能让我玩的开心点吗？",
  ["$lb_old__hairu2"] = "战斗体验该优化了。",
  ["$lb_old__hairu3"] = "来点刺激的！",
}

skel:addEffect("active", {
  anim_type = "support",
  prompt = "#lb_old__hairu",
  can_use = function(self, player)
    return not player:isNude()
  end,
  min_target_num = 1,
  min_card_num = 1,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type ~= Card.TypeBasic
  end,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and #to_select:getPile("$lb_old__hairu") == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    --[[
    if not table.find(room:getAlivePlayers(), function (to)
      return #to:getPile("$lb_old__hairu") > 0
    end) then
      room.logic:getCurrentEvent():findParent(GameEvent.Round):addCleaner(function ()
        skel:onLose(player, false)
      end)
    end
    --]]
    target:addToPile("$lb_old__hairu", effect.cards[1], false, skel.name, player, {})
    room:addTableMarkIfNeed(player, "lb_old__hairu-round", target.id)
    --room:setPlayerMark(target, skel.name, 2)  --8.30
  end,
})
--[[
--8.30
skel:addEffect(fk.RoundEnd, {
  can_refresh = Util.TrueFunc,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    for _, to in ipairs(room:getAlivePlayers()) do
      if #to:getPile("$lb_old__hairu") > 0 then
        room:removePlayerMark(to, skel.name, 1)
        if to:getMark(skel.name) == 0 then
          room:moveCardTo(to:getPile("$lb_old__hairu"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, skel.name, "$lb_old__hairu", true)
        end
      end
    end
  end,
})
--8.30
skel:addEffect(fk.TurnEnd, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark(skel.name) > 0
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, skel.name, 0) --8.30
    room:moveCardTo(player:getPile("$lb_old__hairu"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, skel.name, "$lb_old__hairu", true)
  end,
})
--]]
skel:addLoseEffect(function(self, player, is_death)
  local room = player.room
  for _, p in ipairs(player.room:getAlivePlayers()) do
    if #p:getPile("$lb_old__hairu") > 0 then
      --room:setPlayerMark(p, skel.name, 0) --8.30
      room:moveCardTo(p:getPile("$lb_old__hairu"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, skel.name,
        "$lb_old__hairu", true)
    end
  end
end)

skel:addEffect(fk.PreHpRecover, {
  is_delay_effect = true,
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) then
      local hr = target:getPile("$lb_old__hairu")
      return #hr > 0 and Fk:getCardById(hr[1]).color == Card.Red
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local n = data.num
    data:preventRecover()
    local room = player.room
    --room:setPlayerMark(target, skel.name, 0) --8.30
    room:moveCardTo(target:getPile("$lb_old__hairu"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "lb_old__hairu",
      "lb_old__hairu", true)
    room:damage {
      from = player,
      to = target,
      damage = n,
      skillName = skel.name,
    }
  end,
})

skel:addEffect(fk.DamageCaused, {
  is_delay_effect = true,
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and target then
      local hr = target:getPile("$lb_old__hairu")
      if #hr > 0 then
        local hrc = Fk:getCardById(hr[1])
        return hrc.color == Card.Black
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local n = data.damage
    data:preventDamage()
    local room = player.room
    --room:setPlayerMark(target, skel.name, 0) --8.30
    room:moveCardTo(target:getPile("$lb_old__hairu"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "lb_old__hairu",
      "lb_old__hairu", true)
    room:recover {
      who = data.to,
      num = n,
      skillName = skel.name,
    }
  end,
})

-- 银狼能看到所有的骇入牌
skel:addEffect("visibility", {
  card_visible = function(self, player, card)
    if table.find(Fk:currentRoom().alive_players, function(to)
          return to:getPileNameOfId(card.id) == "$lb_old__hairu"
        end) then
      return player:hasSkill(skel.name, true)
    end
  end
})

return skel
